<template>
    <el-card style="height: 100%;">
        <el-form :model="form" label-width="auto" style="max-width: 600px">
            <el-form-item label="预约分类">
                <el-select v-model="form.departmentId" placeholder="请选择维修的物品">
                    <el-option v-for="(item, index) in departmentInfo" :key="index" :label="item.departmentName" :value="item.departmentId" />
                </el-select>
            </el-form-item>
            <el-form-item label="服务类型">
                <el-select v-model="form.typeId" placeholder="请选择维修方式">
                    <el-option v-for="(item, index) in typeInfo" :key="index" :label="item.typeName" :value="item.typeId" />
                </el-select>
            </el-form-item>
            <el-form-item label="问题描述">
                <el-input v-model="form.problem" type="textarea" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">提交</el-button>
                <el-button>取消</el-button>
            </el-form-item>
        </el-form>
    </el-card>
</template>

<script setup>
import departmentApi from "@/api/departmentApi";
import orderApi from "@/api/orderApi";
import typeApi from "@/api/typeApi";
import { ElMessage } from "element-plus";
import { ref, reactive } from "vue"
const form = ref({
    userId: '',
    departmentId: '',
    problem: '',
    typeId: ''
})

// 业务类型
const departmentInfo = ref([]);
// 服务类型
const typeInfo = ref([]);

const getDepartment = () => {
    departmentApi.getAll()
        .then(resp => {
            if (resp.code === 10000) {
                departmentInfo.value = resp.data;
            }
        });
}
// 获得服务分类
const getType = () => {
    typeApi.getAll()
        .then(resp => {
            if (resp.code === 10000) {
                typeInfo.value = resp.data;
            }
        });
}
const onSubmit = () => {
    let id = sessionStorage.getItem('userInfoUserId');
    form.value.userId = id;
    orderApi.addInfo(form.value)
        .then(resp => {
            if (resp.code === 10000) {
                ElMessage.success(resp.msg);
                form.value = {
                    userId: '',
                    departmentId: '',
                    problem: '',
                    typeId: ''
                };
            }
        });
}
getDepartment();
getType();
</script>

<style lang="scss" scoped></style>
